package com.flex.core.scheduling;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

import com.flex.service.BatchJobBean;

/**
 * 
 * 任务的包装类，不支持并发运行定时任务
 * 
 * @author radio
 * 
 */
public class JobWrapper implements Job {

	/**
	 * 利用反射运行之前存在JobExecutionContext的JobDataMap中的方法
	 */
	public void execute(JobExecutionContext context)
			throws JobExecutionException {
		JobDataMap data = context.getJobDetail().getJobDataMap();
		BatchJobBean batch = (BatchJobBean) data.get("jobObject");
		Method method = (Method) data.get("method");
		try {
			method.invoke(batch);
		} catch (IllegalArgumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
